package com.ssm.common;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mybatis.entity.Page;
import com.mybatis.plugin.PagePlug;
import com.ssm.exception.ServiceException;

public abstract class CommonAbstractService<T> {

	protected   Logger log = LoggerFactory.getLogger(this.getClass());
	
	protected abstract CommonDao<T> getCommonDao();
	
	protected  boolean isSJar()
	{
		
		return false;
	}

	public void addEntrity(T t) throws ServiceException {
			getCommonDao().addSingleEntity(t);
	}

	public void addEntrityBatch(List<T> list) throws ServiceException {
			getCommonDao().batchAddEntity(list);
	}

	public void updateEntrity(T t) throws ServiceException {
			getCommonDao().updateSingleEntity(t);
		

	}
	
	public void updateEntrityByMap(Map<String, Object> map) throws ServiceException
	{
			getCommonDao().updateSingleEntityById(map);
	}

	public void deleteEntrity(String id) throws ServiceException {
			getCommonDao().deleteSingleEntityById(id);
		
	}

	public void deleteEntrityBatch(List<String> ids) throws ServiceException {
			getCommonDao().BatchDeleteEntity(ids);
		
	}

	public T queryById(String id) throws ServiceException {
			return getCommonDao().findSingleEntity(id);
		
	}

	public List<T> queryByEntrity(T t) throws ServiceException {
			return getCommonDao().findSomeEntity(t);
		
	}

	public Page<T> queryByPageInfo(Map<String, Object> map, int start, int size) throws ServiceException {
		if(isSJar())
		{
			PagePlug.startPage(start, size);
			List<T> list = getCommonDao().findSomeEntityByMap(map);
			return (Page<T>)list;
		}
		return null;
	}

	public enum JurisdictionRange {

		all, one;

	}
}
